package com.hsjk.szwj.module.member.dal.mysql.user;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hsjk.szwj.framework.common.pojo.PageResult;
import com.hsjk.szwj.framework.mybatis.core.mapper.BaseMapperX;
import com.hsjk.szwj.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.hsjk.szwj.module.member.controller.admin.user.vo.AdminMemberPageReqVO;
import com.hsjk.szwj.module.member.controller.admin.user.vo.AdminMemberRespVO;
import com.hsjk.szwj.module.member.dal.dataobject.user.MemberUserDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Arrays;
import java.util.List;

/**
 * 会员 User Mapper
 */
@Mapper
public interface MemberUserMapper extends BaseMapperX<MemberUserDO> {

    default MemberUserDO selectByMobile(String mobile) {
        return selectOne(MemberUserDO::getMobile, mobile);
    }

    default List<MemberUserDO> selectListByNicknameLike(String nickname) {
        return selectList(new LambdaQueryWrapperX<MemberUserDO>()
                .likeIfPresent(MemberUserDO::getNickname, nickname));
    }

    default MemberUserDO selectByOpenId(String openId) {
        return selectOne(MemberUserDO::getOpenId, openId);
    }

    default MemberUserDO selectByUnionId(String unionId) {
        return selectOne(MemberUserDO::getUnionId, unionId);
    }

    default PageResult<MemberUserDO> selectPage(AdminMemberPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MemberUserDO>()
                .orderByDesc(Arrays.asList(MemberUserDO::getCreateTime, MemberUserDO::getCreateTime)));
    }

    IPage<AdminMemberRespVO> getMemberUserPageList(Page<AdminMemberPageReqVO> page,
                                                   @Param("param") AdminMemberPageReqVO reqVO);

}
